<template>
  <!-- <el-button
    size="small"
    type="success"
    v-if="props.scope.row.status != 3"
    @click="sendPost(props.scope.$index, props.scope.row)"
    >{{ $t('om.Convertedtomailing') }}
  </el-button> -->
  <el-button
    size="small"
    type="primary"
    v-if="props.scope.row.patchStatus != 2"
    @click="notPosted(props.scope.$index, props.scope.row)"
    >{{ $t('om.Notsticker') }}
  </el-button>
</template>
<script setup>
import {
  addBomMatchList,
  confirmBomMatchId,
  deleteBomMatchList,
  updateBomExpress,
} from '@/server/api/biz.js';
import { ref } from 'vue';
// TODO
const props = defineProps({
  scope: {
    type: Object,
    required: true,
  },
});
const emit = defineEmits(['updateData', 'changeModel']);

/**
 *  更换型号
 * @param {*} row
 */
const changeType = (index, row) => {
  emit('changeModel', index, row);
};

/**
 * 选中型号
 * @param {*} row
 */
const onSelectedAdress = (row) => {
  // ruleForm.shippingAddress = row;
};

/**
 * 改为邮寄
 * @param {*} index
 * @param {*} row
 */
const sendPost = (index, row) => {
  console.log(index, row);
  updateBomExpress({ bomMatchListId: row.id }).then((res) => {
    console.log(res);
    if (res.code == 200) {
      emit('updateData');
      ElMessage.success(t('mall.successfully_changed_to_mail'));
    } else {
      ElMessage.error(res.message);
    }
  });
};

/**
 * 不贴
 * @param {*} index
 * @param {*} row
 */
const notPosted = (index, row) => {
  console.log(index, row);
  deleteBomMatchList({ bomMatchListId: row.id }).then((res) => {
    console.log(res);
    if (res.code == 200) {
      emit('updateData');
       ElMessage.success(t('mall.delete_successful'));
    } else {
      ElMessage.error(res.message);
    }
  });
};

/**
 * 加入贴片
 * @param {*} index
 * @param {*} row
 */
const addPatch = (index, row) => {
  console.log(index, row);
  addBomMatchList({ bomMatchListId: row.id }).then((res) => {
    console.log(res);
    if (res.code == 200) {
      emit('updateData');
    } else {
      ElMessage.error(res.message);
    }
  });
};

/**
 * 确认
 * @param {*} index
 * @param {*} row
 */
const confirm = (index, row) => {
  console.log(index, row);
  confirmBomMatchId({ bomMatchListId: row.id }).then((res) => {
    console.log(res);
    if (res.code == 200) {
      emit('updateData');
      ElMessage.success(t('mall.confirmation_successful'));
    } else {
      ElMessage.error(res.message);
    }
  });
};
</script>

<style lang="scss" scoped>
.m-t-5 {
  margin-top: 5px;
}
::v-deep(.el-button--small) {
  width: 75px;
}
</style>
